home *** CD-ROM | disk | FTP | other *** search
- Path: cs.tu-berlin.de!news
- From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
- Newsgroups: comp.lang.c++
- Subject: Re: 'chained': It would be nice if...
- Date: Wed, 17 Apr 1996 16:53:26 +0200
- Organization: Technical University of Berlin
- Message-ID: <317505E6.7F7F@cs.tu-berlin.de>
- References: <31756DEC.5215@zurich.ibm.com>
- NNTP-Posting-Host: 130.149.17.230
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Keith Whittingham wrote:
- >
- > Three or four times I've find myself needing a construct which I
- > think is missing from C++ (or at least is inaccessable).
- >
- > A keyword, say 'chained', to have a similar effect to that of
- > the virtual destructor. e.g.
- >
- > class Base
- > {
- > public:
- > virtual void vMember(void);
- > chained void cMember(void);
- > };
- >
- > class Derived:
- > public Base
- > {
- > public:
- > void vMember(void);
- > void cMember(void);
- > };
- >
- > Calling Derived::vMember() executes the code contained in the body
- > Derived::vMember() whereas calling Derived::cMember() would
- > execute the code contained in the body Base::cMember() and then
- > the code contained in Derived::cMember().
-
- How about:
-
- class Base
- {
- public:
- void cMember(void)
- {
- Base_cMember();
- Derived_cMember();
- }
- protected:
- virtual void Derived_cMember();
- private:
- void Base_cMember();
- };
-
- Every time cMember is called the unique private code in Base_cMember is
- executed. Then Derived_cMember is called which can be overridden in derived
- classes.
-
- Bye
-
- Roman
-